#!/bin/bash

set -e # exit on error
set -x # echo commands

if  [ "${NO_GIT_FETCH}" != "1" ]; then
    git fetch --quiet origin master
fi

# install TravisCI "artifacts" util, see https://github.com/travis-ci/artifacts
wget -qO- "https://raw.githubusercontent.com/travis-ci/artifacts/master/install" |bash

# install Miniconda
PYTHON="${PYTHON:-3.6}"
MINICONDA_FILENAME=Miniconda${PYTHON:0:1}-latest-Linux-x86_64.sh
if  [ "${NO_INSTALL_CONDA}" != "1" ]; then
    wget -nv "http://repo.continuum.io/miniconda/${MINICONDA_FILENAME}"
    bash ${MINICONDA_FILENAME} -b -f -p ${HOME}/miniconda

fi

# if emergency, temporary package pins are necessary, they can go here
PINNED_PKGS=$(cat <<EOF
EOF
)
mkdir -p $HOME/miniconda/conda-meta
echo -e "$PINNED_PKGS" > $HOME/miniconda/conda-meta/pinned

# install conda packages in root env
conda install --yes --quiet ${CONDA_REQS}

# set default conda channels
conda config --set auto_update_conda off
conda config --append channels bokeh
conda config --get channels

# create and activate test env
conda create -n testenv --yes --quiet python=${PYTHON} pyyaml jinja2

# conda init / activate unfortunately do not work on TravisCI so this path
# is added in .travis.yml
# export PATH=${HOME}/miniconda/envs/testenv/bin:${PATH}
